package ch06.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class BaseAction {
    public void execute(HttpServletRequest request,
                        HttpServletResponse response){
        try {
            Method method =this.getClass().getDeclaredMethod(
                    request.getParameter("methodName")
                    ,HttpServletRequest.class
                    , HttpServletResponse.class
            );
            method.setAccessible(true);
            method.invoke(this,request,response);   //执行方法
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }
}
